"""
查询FC2
is_download为N的的磁力链接并打印，将is_download置为Y
"""

import mysql.connector
import common.gyblog as log

LOG = log.get_logger()
MYSQL_DB = mysql.connector.connect(
    host="192.168.0.180",
    user="root",
    passwd="123456",
    database="movies_record"
)


def update_fc2(num, is_download):
    db_cursor = MYSQL_DB.cursor()
    sql = "UPDATE fc2_record SET is_download = '{}' WHERE num = '{}'".format(is_download, num)
    db_cursor.execute(sql)
    MYSQL_DB.commit()


def query_fc2():
    db_cursor = MYSQL_DB.cursor()
    query_sql = "SELECT * FROM fc2_record WHERE is_download = 'N'"
    db_cursor.execute(query_sql)
    ans = db_cursor.fetchall()
    if len(ans) > 0:
        for a in ans:
            LOG.info(a[3])
            print(a[3])
            update_fc2(a[1], 'Y')
    print(len(ans))


if __name__ == '__main__':
    query_fc2()
